import dayjs from "dayjs"
// 疾病史
export const diseaseList = [
    {label: "暂无", click: false},
    {label: "高血压", click: false},
    {label: "糖尿病", click: false},
    {label: "心脏病", click: false},
    {label: "过敏性疾病", click: false},
    {label: "哮喘", click: false},
    {label: "白癜风", click: false},
    {label: "癫痫", click: false},
    {label: "其他", click: false},
]

//过敏史
export const allergyList = [
    {label: "暂无", click: false},
    {label: "青霉素", click: false},
    {label: "头孢类", click: false},
    {label: "普鲁卡因", click: false},
    {label: "破伤风抗毒素", click: false},
    {label: "泛影葡胺", click: false},
    {label: "维生素B1", click: false},
    {label: "磺胺类", click: false},
    {label: "地卡因", click: false},
    {label: "阿司匹林", click: false},
    {label: "其他", click: false},
]


//个人习惯
export const habitList = [
    {label: "低头族", click: false},
    {label: "久坐", click: false},
    {label: "久站", click: false},
    {label: "跷二郎腿", click: false},
    {label: "吸烟", click: false},
    {label: "不常锻炼", click: false},
    {label: "不喜喝水", click: false},
    {label: "喝酒", click: false},
    {label: "熬夜", click: false},
    {label: "饭后卧床", click: false},
    {label: "强忍大小便", click: false},
    {label: "如厕玩手机", click: false},
    {label: "其他", click: false}
]


export const txtAreaStyle = {
    "--color": "#000000", 
    "--font-size": "0.31rem", 
    "--placeholder-color": "rgba(0, 0, 0, 0.35)", 
    "width": "100%",
    "height": "1.38rem",
    "fontFamily": "MiSans-Regular",
    "paddingTop": "0.23rem",
    "paddingLeft": "0.23rem",
    "boxSizing": "border-box"
}

export const genderStyle = { '--height': '2rem', "--item-height": "0.8rem", "--item-font-size": "0.31rem" };
export const dateStyle = { '--height': '2.4rem', "--item-height": "0.6rem" };
export const weightStyle = { '--height': '3.25rem', "--item-height": "1rem", "--item-font-size": "0.31rem" };
export const smokeStyle = { '--height': '2.16rem', "--item-height": "1rem", "--item-font-size": "0.31rem" };


//日期
const getTotalDate = () => {
    const list = [];
    const date = new Date();
    for(let i = 1930; i <= date.getFullYear(); i++) {
        const map = {
            label: `${i}年`,
            value: i.toString(),
            children: []
        };
        for(let j = 1; j <= 12; j++) {
            map.children.push({
                label: `${j}月`,
                value: (j < 10 ? '0' + j : j).toString(),
                children: []
            })
            const date = new Date(map.value, j, 0).getDate();
            for(let k = 1; k <= date; k++) {
                map.children[j-1].children.push({
                    label: `${k}日`,
                    value: (k < 10 ? '0' + k : k).toString(),
                })
            }
        }
        list.push(map);
    }
    return list;
}

// 性别
const genderColumns = [
    [
        {label: "男", value: 1},
        {label: "女", value: 2},
    ]
];
// 身高
const getStatureList = () => {
    const statureList = [];
    for(let i = 60; i <= 250; i++) {
        statureList.push({label: `${i}`, value: i});
    }
    return [statureList];
}

// 体重
const getWeightList = () => {
    const weightList = [];
    for(let i = 30; i <= 200; i++) {
        weightList.push({label: `${i}`, value: i});
    }
    return [weightList];
}

//血型
const bloodColumns = [
    [
        {label: "A型", value: "A型"},
        {label: "B型", value: "B型"},
        {label: "AB型", value: "AB型"},
        {label: "O型", value: "O型"},
        {label: "未知", value: "未知"},
    ]
];

//香烟
const smokeYears = [
    {label: "1年", value: "1年", children: []},
    {label: "2年", value: "2年", children: []},
    {label: "3年", value: "3年", children: []},
    {label: "4年", value: "4年", children: []},
    {label: "5年", value: "5年", children: []},
    {label: "6年", value: "6年", children: []},
    {label: "7年", value: "7年", children: []},
    {label: "8年", value: "8年", children: []},
    {label: "9年", value: "9年", children: []},
    {label: "10年", value: "10年", children: []},
    {label: "10年以上", value: "10年以上", children: []}
];

const smokeNum = [
    {label: "1根", value: "1根"},
    {label: "2根", value: "2根"},
    {label: "3根", value: "3根"},
    {label: "4根", value: "4根"},
    {label: "5根", value: "5根"},
    {label: "6根", value: "6根"},
    {label: "7根", value: "7根"},
    {label: "8根", value: "8根"},
    {label: "9根", value: "9根"},
    {label: "10根", value: "10根"},
    {label: "11根", value: "11根"},
    {label: "12根", value: "12根"},
    {label: "13根", value: "13根"},
    {label: "14根", value: "14根"},
    {label: "15根", value: "15根"},
    {label: "16根", value: "16根"},
    {label: "17根", value: "17根"},
    {label: "18根", value: "18根"},
    {label: "19根", value: "19根"},
    {label: "20根", value: "20根"},
    {label: "20根以上", value: "20根以上"},
];
const getSmokeList = () => {
    const smokes = [
        {
            label: "是", 
            value: 1, 
            children: []
        },
        {
            label: "否", 
            value: 0, 
            children: [
                {
                    label: "--", 
                    value: "--",
                    children: [
                        {
                            label: "--", 
                            value: "--", 
                        }
                    ]
                }
            ]
        },
    ];
    
    for(let i = 0; i < smokeYears.length; i++) {
        const map = {
            label: smokeYears[i].label, value: smokeYears[i].label, children: []
        }
        for(let j = 0; j < smokeNum.length; j++) {
            map.children.push({
                label: smokeNum[j].label, value: smokeNum[j].label
            })
        }
        smokes[0].children.push(map);
    }
    return smokes;
}

//标题
export const titList = ['性别', '出生日期', '身高', '体重', '血型', '吸烟史', '饮酒史'];

//饮酒史数据
const drinkYears = ['1年', '2年', '3年', '4年', '5年', '6年', '7年', '8年', '9年', '10年', '10年以上'];
const drinkTypes = ['白酒', '啤酒', '红酒', '以上都有'];

export const drinkAmountMap = {
    "少量": 1,
    "适量": 2,
    "大量": 3,
    "1": "少量",
    "2": "适量",
    "3": "大量"
}
const drinkAmounts = ['少量', '适量', '大量']
const getDrinkList = () => {
    const drinks = [
        {
            label: "是", 
            value: 1, 
            children: []
        },
        {
            label: "否", 
            value: 0, 
            children: [
                {
                    label: "--", 
                    value: "--",
                    children: [
                        {
                            label: "--", 
                            value: "--", 
                            children: [
                                {
                                    label: "--", 
                                    value: "--", 
                                }
                            ]
                        }
                    ]
                }
            ]
        },
    ];
    for(let i = 0; i < drinkYears.length; i++) {
        const map = {
            label: drinkYears[i], value: drinkYears[i], children: []
        }
        for(let j = 0; j < drinkTypes.length; j++) {
            map.children.push({
                label: drinkTypes[j], value: drinkTypes[j], children: []
            })
            for (let k = 0; k < drinkAmounts.length; k++) {
                map.children[j].children.push(
                    {label: drinkAmounts[k], value: drinkAmounts[k]}
                )
            }
        }
        drinks[0].children.push(map);
    }
    return drinks;

}

/**
 * 时间选择
 * @returns 
 */
const getDurationList = () => {
    const hourCurrent = [];
    for(let i = 0; i < 24; i++) {
        hourCurrent.push((i < 10 ? '0'+i : ''+i));
    }
    const minuteCurrent = [];
    for(let i = 0; i < 6; i++) {
        const end = i * 10;
        minuteCurrent.push((end < 10 ? '0'+end : ''+end));
    }

    return [hourCurrent, minuteCurrent];
}

export const targetMap = {
    genderColumns: genderColumns,
    weightList: getWeightList(),
    totalDate: getTotalDate(),
    statureList: getStatureList(),
    bloodColumns: bloodColumns,
    smokeList: getSmokeList(),
    drinkList: getDrinkList(),
    durationList: getDurationList()
}

/**
 * 获取当前时间
 * @returns 
 */
export const getcurrentDates = () => {
    const current = dayjs();

    //获取年
    const year = current.year();

    //获取月
    const month = current.month() + 1;

    //获取日
    const day = current.date();

    //封装成数组
    return [("" + year), (month < 10 ? "0" + month : ("" + month)), (day < 10 ? "0" + day : ("" + day))]
}


export const getHeartDatas = (param) => {
    const echartData = {
        xAxis: [],
        series: [],
    };
    
    if(param && Object.keys(param).length !== 0) {
        //循环map
        for (let key in param) {
            echartData.xAxis.push(dayjs.unix(Number(key)).format("HH:mm"));
            echartData.series.push(param[key]);
        }
        return echartData;
    }
    
    if(echartData.xAxis.length === 0 && echartData.series.length === 0) {
        echartData.xAxis = ['暂无数据'];
        echartData.series = [0];
    }
    return echartData;
}


/**
 * 根据高压和低压获取血压的状态
 * @param {*} max 
 * @param {*} min
 */
export const getBloodStatusByMaxAndMin = (max, min) => {
    if((max > 90 && max < 120) && (min > 60 && min < 80)) {
        return "正常";
    }

    if((max >= 120 && max <= 139) || (min >= 80 && min <= 89)) {
        return "正常高值";
    }

    if((max >= 140) || (min >= 90)) {
        return "高血压";
    }

    if((max <= 90) || (min <= 60)) {
        return "偏低";
    }
}